package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageDTO;
import com.sky.entity.Setmeal;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface SetmealMapper {


    //套餐分页查询-->App套餐显示
    List<SetmealVO> findList(SetmealPageDTO setmealPageDTO);

    //新增套餐
    @AutoFill("insert")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into setmeal values (null,#{categoryId},#{name},#{price},#{status},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void save(Setmeal setmeal);

    //回显套餐->根据id查询套餐
    @Select("select s.*,c.name as categoryName from setmeal s left join category c on s.category_id = c.id where s.id = #{id}")
    SetmealVO findById(Long id);

    //修改
    @AutoFill("update")
    void update(Setmeal setmeal);

    //套餐的起售、停售
    @AutoFill("update")
    @Update("")
    void updateStatus(Long id, Integer status);

    //批量删除
    void deleteByIds(Long[] ids);
    //根据分类id统计套餐数量->查询当前分类id下是否还有套餐
    @Select("select count(*) from setmeal where category_id = #{categoryId}")
    int countByCategoryId(Long categoryId);
}
